package com.hontech.bvapp2.utils

import android.os.Environment
import java.io.Closeable
import java.io.File
import java.io.FileOutputStream


fun Closeable.safeClose() {
    try {
        this.close()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

class TimeoutException(msg: String) : Exception(msg)

class ExecException(msg: String) : Exception(msg)


fun Int.isBitSet(bit: Int) = (this and (0x01 shl bit)) != 0

suspend fun ByteArray.writeToFile(name: String): String {
    return runIO {
        val file = File(Environment.getExternalStorageDirectory(), name)
        val output = FileOutputStream(file)
        output.use { it.write(this) }
        file.path
    }
}

